#include "tela.h"
#include <iostream>

using namespace std;

Tela::Tela(int left, int right, int bottom, int up, QWidget *parent)
    : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
    this->xi = left;
    this->xf = right;
    this->yi = bottom;
    this->yf = up;
}

Tela::~Tela()
{
}

void Tela::initializeGL()
{
    qglClearColor(Qt::black);
    glShadeModel(GL_FLAT);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glViewport(0, 0, this->width(), this->height());
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluOrtho2D(this->xi, this->xf, this->yi, this->yf);
}

void Tela::clear()
{
    qglClearColor(Qt::black);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluOrtho2D(this->xi, this->xf, this->yi, this->yf);
    glPointSize(2);
    glBegin(GL_POINTS);
}

void Tela::paintGL()
{
    glEnd();
    glFlush();
}

void Tela::paintPoint(int x, int y, int r, int g, int b)
{
    qglColor(QColor(r, g, b));
    glVertex2i(x, y);
}
/*
void Tela::paintLines(PlanoTela plano, Ponto *ponto, int length, QColor color, float width)
{
    qglColor(color);
    glLineWidth(width);
    glBegin(GL_LINE_STRIP);
    glVertexSelect(plano, ponto, length);
    glEnd();
    glFlush();
}

void Tela::glVertexSelect(PlanoTela plano, Ponto *ponto, int length)
{
    switch(plano) {
        case XY:
            for(int i = 0; i < length; i++) {
                glVertex2i(ponto[i].getX(), ponto[i].getY());
            }
            break;
        case YZ:
            for(int i = 0; i < length; i++) {
                glVertex2i(ponto[i].getY(), ponto[i].getZ());
            }
            break;
        case XZ:
            for(int i = 0; i < length; i++) {
                glVertex2i(ponto[i].getX(), ponto[i].getZ());
            }
            break;
    }
}
*/
